﻿// ----------------------------------------------------------------
// Description : 实体类,该文件由MyGeneration生成
// Author      : 
// Create date : 2010-1-18
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ITOMMS.Entity
{
    /// <summary>
    ///	tbNotice Entity
    ///	tbNotice Entity通知表
    /// </summary>
    [Serializable]
    public class tbNoticeEntity : BaseEntity<tbNoticeEntity, int>
    {

        #region 私有成员

        private int _ID;
        private string _Title;
        private string _Content;
        private DateTime? _CreateDate;
        private int? _CreateBy;
        private DateTime? _ModifyDate;
        private int? _ModifyBy;
        private string _Remarks;
        private int? _State;
        private int? _ViewNum;
        private int _Type;
        private int _SEQNO;
        #endregion



        #region 默认( 空 ) 构造函数
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public tbNoticeEntity()
        {
            _ID = 0;
            _Title = String.Empty;
            _Content = String.Empty;
            _CreateDate = null;
            _CreateBy = null;
            _ModifyDate = null;
            _ModifyBy = null;
            _Remarks = String.Empty;
            _State = null;
            _ViewNum = null;
            _Type = 0;
            _SEQNO = 0;
        }
        #endregion

        #region 属性值校验

        /// <summary>
        /// 属性值校验
        /// </summary>
        public bool CheckValues()
        {
            bool bResult = true;
            string strError = "";

            if (_ID == 0)
            {
                bResult = false;
                strError += "\r\n 非空值不能为: " + _ID;
            }

            if (!bResult)
                throw new ArgumentOutOfRangeException(strError);
            return bResult;

        }

        #endregion




        #region Required Fields Only Constructor

        /// <summary>
        /// required (not null) fields only constructor
        /// </summary>
        public tbNoticeEntity(
        int para_ID)
            : this()
        {
            _ID = para_ID;
            _Title = String.Empty;
            _Content = String.Empty;
            _CreateDate = null;
            _CreateBy = null;
            _ModifyDate = null;
            _ModifyBy = null;
            _Remarks = String.Empty;
            _State = null;
            _ViewNum = null;
            _Type = 0;
        }
        #endregion


        #region 公有属性

        /// <summary>
        /// 行号，顺序号。系统默认的属性,对这个属性不要作操作.属性值在架构中已经处理
        /// </summary>
        public virtual int SEQNO
        {
            get { return _SEQNO; }
            set { _SEQNO = value; }
        }


        /// <summary>
        /// IDID
        /// </summary>		
        public virtual int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        /// <summary>
        /// Title标题
        /// </summary>		
        public virtual string Title
        {
            get { return _Title; }
            set
            {

                if (value != null)
                    if (value.Length > 100)
                        throw new ArgumentOutOfRangeException("Invalid value for Title", value, value.ToString());

                _Title = value;
            }
        }

        /// <summary>
        /// Content内容
        /// </summary>		
        public virtual string Content
        {
            get { return _Content; }
            set
            {

                if (value != null)
                    if (value.Length > 2147483647)
                        throw new ArgumentOutOfRangeException("Invalid value for Content", value, value.ToString());

                _Content = value;
            }
        }

        /// <summary>
        /// CreateDate创建时间
        /// </summary>		
        public virtual DateTime? CreateDate
        {
            get { return _CreateDate; }
            set { _CreateDate = value; }
        }

        /// <summary>
        /// CreateBy创建人
        /// </summary>		
        public virtual int? CreateBy
        {
            get { return _CreateBy; }
            set { _CreateBy = value; }
        }

        /// <summary>
        /// ModifyDate修改时间
        /// </summary>		
        public virtual DateTime? ModifyDate
        {
            get { return _ModifyDate; }
            set { _ModifyDate = value; }
        }

        /// <summary>
        /// ModifyBy修改人
        /// </summary>		
        public virtual int? ModifyBy
        {
            get { return _ModifyBy; }
            set { _ModifyBy = value; }
        }

        /// <summary>
        /// Remarks备注
        /// </summary>		
        public virtual string Remarks
        {
            get { return _Remarks; }
            set
            {

                if (value != null)
                    if (value.Length > 100)
                        throw new ArgumentOutOfRangeException("Invalid value for Remarks", value, value.ToString());

                _Remarks = value;
            }
        }

        /// <summary>
        /// State状态
        /// </summary>		
        public virtual int? State
        {
            get { return _State; }
            set { _State = value; }
        }

        /// <summary>
        /// ViewNum浏览次数
        /// </summary>		
        public virtual int? ViewNum
        {
            get { return _ViewNum; }
            set { _ViewNum = value; }
        }

        /// <summary>
        /// Type1.全部 2.公司内部
        /// </summary>		
        public virtual int Type
        {
            get { return _Type; }
            set { _Type = value; }
        }



        #endregion


        #region DAO操作


        /// <summary>
        /// 获取所有实体的列表
        /// </summary>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAll()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice] ");

            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }

        /// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  select count([ID])  from [tb_Notice] ");

            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords(string sqlCondition)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  select count([ID])  from [tb_Notice]  ");

            if (sqlCondition.Trim() != "")
            {
                strSql.Append(" where " + sqlCondition);
            }
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }


        /// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="PageSize">每页大小</param>
        /// <param name="CurrentPageIndex">当前页码</param>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAllByQuery(string strWhere, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }

            strSql.Append("select top ").Append(PageSize).Append("  [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice] where ");

            if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
            strSql.Append(" ID not in ( ");
            strSql.Append(" select top ").Append(PageSize * (CurrentPageIndex - 1)).Append("  [ID] from [tb_Notice] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" ) ");

            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }


        /// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="PageSize">每页大小</param>
        /// <param name="CurrentPageIndex">当前页码</param>
        /// <param name="strSort">ex:order by id desc</param>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAllByQuery(string strWhere, string strSort, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }

            strSql.Append("select top ").Append(PageSize).Append("  [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice] where ");

            if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
            strSql.Append(" ID not in ( ");
            strSql.Append(" select top ").Append(PageSize * (CurrentPageIndex - 1)).Append("  [ID] from [tb_Notice] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere + " ").Append(strSort);
            }
            strSql.Append(" ) ").Append(strSort);

            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }


        /// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAllByQuery(string strWhere)
        {
            strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from tb_Notice ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }



        /// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="parameters">sql条件中的参数</param>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }






        /// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters, int rowNumber)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top ").Append(rowNumber).Append("  [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }


        /// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句: AND AA=@AA</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tbNoticeEntity> GetAllByQuery(string strWhere, int rowNumber)
        {
            strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top ").Append(rowNumber).Append("  [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where  " + strWhere);
            }
            List<tbNoticeEntity> list = new List<tbNoticeEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }







        /// <summary>
        /// 按主键查询对应的实体
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public override tbNoticeEntity GetById(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] from [tb_Notice]  where ID= @ID ");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            tbNoticeEntity entity = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    entity = ReaderBind(dataReader);
                }
            }
            return entity;

        }


        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save()
        {

            if (this.ID == 0)
            {
                this.ID = GetMax("tb_Notice");
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into  tb_Notice (");
            strSql.Append("[ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] )");
            strSql.Append(" values (");
            strSql.Append("@ID,@Title,@Content,@CreateDate,@CreateBy,@ModifyDate,@ModifyBy,@Remarks,@State,@ViewNum,@Type)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID);
            db.AddInParameter(dbCommand, "Title", DbType.String, this.Title);
            db.AddInParameter(dbCommand, "Content", DbType.String, this.Content);
            if (this.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
            }
            if (this.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
            }
            if (this.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
            }
            if (this.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
            }
            db.AddInParameter(dbCommand, "Remarks", DbType.String, this.Remarks);
            if (this.State == null)
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, this.State.Value);
            }
            if (this.ViewNum == null)
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, this.ViewNum.Value);
            }
            db.AddInParameter(dbCommand, "Type", DbType.Int32, this.Type);

            return db.ExecuteNonQuery(dbCommand);


        }



        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save(tbNoticeEntity entity)
        {

            if (entity.ID == 0)
            {
                entity.ID = GetMax("tb_Notice");
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into  tb_Notice (");
            strSql.Append("[ID],[Title],[Content],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State],[ViewNum],[Type] )");
            strSql.Append(" values (");
            strSql.Append("@ID,@Title,@Content,@CreateDate,@CreateBy,@ModifyDate,@ModifyBy,@Remarks,@State,@ViewNum,@Type)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
            db.AddInParameter(dbCommand, "Title", DbType.String, entity.Title);
            db.AddInParameter(dbCommand, "Content", DbType.String, entity.Content);
            if (entity.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
            }
            if (entity.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
            }
            if (entity.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
            }
            if (entity.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
            }
            db.AddInParameter(dbCommand, "Remarks", DbType.String, entity.Remarks);
            if (entity.State == null)
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, entity.State.Value);
            }
            if (entity.ViewNum == null)
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, entity.ViewNum.Value);
            }
            db.AddInParameter(dbCommand, "Type", DbType.Int32, entity.Type);

            return db.ExecuteNonQuery(dbCommand);


        }


        /// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate(tbNoticeEntity entity)
        {

            if (entity.ID == 0)
            {
                if (Save(entity) > 0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update(entity);
            }
        }

        /// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate()
        {

            if (this.ID == 0)
            {
                if (Save() > 0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update();
            }
        }

        /// <summary>
        /// 是否存在对应主键ID的记录
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override bool IsExist(int ID)
        {
            Database db = GetDatabase();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tb_Notice where ID=@ID ");

            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, ID);//这里为ID是因为原有代码把主键都变成了ID.
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 删除对应的实体
        /// </summary>
        /// <param name="entity"></param>
        public override int Delete(tbNoticeEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_Notice ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
            return db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// 删除主键ID对应的记录
        /// </summary>
        /// <param name="id"></param>
        public override int Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_Notice ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            return db.ExecuteNonQuery(dbCommand);
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public override int Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_Notice set ");
            strSql.Append("[ID]=@ID,[Title]=@Title,[Content]=@Content,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[ModifyBy]=@ModifyBy,[Remarks]=@Remarks,[State]=@State,[ViewNum]=@ViewNum,[Type]=@Type ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID);
            db.AddInParameter(dbCommand, "Title", DbType.String, this.Title);
            db.AddInParameter(dbCommand, "Content", DbType.String, this.Content);
            if (this.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
            }
            if (this.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
            }
            if (this.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
            }
            if (this.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
            }
            db.AddInParameter(dbCommand, "Remarks", DbType.String, this.Remarks);
            if (this.State == null)
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, this.State.Value);
            }
            if (this.ViewNum == null)
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, this.ViewNum.Value);
            }
            db.AddInParameter(dbCommand, "Type", DbType.Int32, this.Type);


            return db.ExecuteNonQuery(dbCommand);

        }





        /// <summary>
        /// 更新一条数据
        /// </summary>
        public override int Update(tbNoticeEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_Notice set ");
            strSql.Append("[ID]=@ID,[Title]=@Title,[Content]=@Content,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[ModifyBy]=@ModifyBy,[Remarks]=@Remarks,[State]=@State,[ViewNum]=@ViewNum,[Type]=@Type ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
            db.AddInParameter(dbCommand, "Title", DbType.String, entity.Title);
            db.AddInParameter(dbCommand, "Content", DbType.String, entity.Content);
            if (entity.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
            }
            if (entity.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
            }
            if (entity.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
            }
            if (entity.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
            }
            db.AddInParameter(dbCommand, "Remarks", DbType.String, entity.Remarks);
            if (entity.State == null)
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "State", DbType.Int32, entity.State.Value);
            }
            if (entity.ViewNum == null)
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ViewNum", DbType.Int32, entity.ViewNum.Value);
            }
            db.AddInParameter(dbCommand, "Type", DbType.Int32, entity.Type);


            return db.ExecuteNonQuery(dbCommand);

        }







        /// <summary>
        /// 对象实体绑定数据
        ///生成构造为list的构造器
        /// </summary>
        private tbNoticeEntity ReaderBind(IDataReader dataReader, int seq)
        {
            ITOMMS.Entity.tbNoticeEntity entity = new ITOMMS.Entity.tbNoticeEntity();
            entity.SEQNO = seq;
            object obj;
            obj = dataReader["ID"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ID = (int)obj;
            }
            entity.Title = dataReader["Title"].ToString();
            entity.Content = dataReader["Content"].ToString();
            obj = dataReader["CreateDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateDate = (DateTime)obj;
            }
            obj = dataReader["CreateBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateBy = (int)obj;
            }
            obj = dataReader["ModifyDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyDate = (DateTime)obj;
            }
            obj = dataReader["ModifyBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyBy = (int)obj;
            }
            entity.Remarks = dataReader["Remarks"].ToString();
            obj = dataReader["State"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.State = (int)obj;
            }
            obj = dataReader["ViewNum"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ViewNum = (int)obj;
            }
            obj = dataReader["Type"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.Type = (int)obj;
            }           

            return entity;
        }


        /// <summary>
        /// 对象实体绑定数据
        ///生成构造为list的构造器
        /// </summary>
        private tbNoticeEntity ReaderBind(IDataReader dataReader)
        {
            ITOMMS.Entity.tbNoticeEntity entity = new ITOMMS.Entity.tbNoticeEntity();
            object obj;
            obj = dataReader["ID"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ID = (int)obj;
            }
            entity.Title = dataReader["Title"].ToString();
            entity.Content = dataReader["Content"].ToString();
            obj = dataReader["CreateDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateDate = (DateTime)obj;
            }
            obj = dataReader["CreateBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateBy = (int)obj;
            }
            obj = dataReader["ModifyDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyDate = (DateTime)obj;
            }
            obj = dataReader["ModifyBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyBy = (int)obj;
            }
            entity.Remarks = dataReader["Remarks"].ToString();
            obj = dataReader["State"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.State = (int)obj;
            }
            obj = dataReader["ViewNum"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ViewNum = (int)obj;
            }
            obj = dataReader["Type"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.Type = (int)obj;
            }      

            return entity;
        }



        #endregion

    }
}
